package com.ctgu.server.controller;


import com.ctgu.server.dao.dto.AttendanceUserDto;
import com.ctgu.server.dao.vo.Result;
import com.ctgu.server.service.AttendanceGroupUserService;
import com.ctgu.server.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 考勤组与用户关系表 前端控制器
 * </p>
 *
 * @author ctgu
 * @since 2023-06-13
 */
@RestController
@RequestMapping("/server/attendanceGroupUser")
@CrossOrigin
@Api(tags = "打卡信息操作接口")
public class AttendanceGroupUserController {
    @Autowired
    private AttendanceGroupUserService attendanceGroupUserService;
    @ApiOperation(notes = "新增考勤组成员",value = "新增考勤组成员")
    @PostMapping("/insert")
    public Result addAttendanceGroupUser(@RequestParam AttendanceUserDto attendanceUserDto){
        if(attendanceUserDto.getOpId()==null||attendanceUserDto.getAttGrId()==null||attendanceUserDto.getUserList()==null){
            return ResultUtil.error("参数缺失！");
        }
        return attendanceGroupUserService.addAttendanceGroupUser(attendanceUserDto.getOpId(),attendanceUserDto.getAttGrId(),attendanceUserDto.getUserList());
    }
    @ApiOperation(notes = "移出考勤组成员",value = "移出考勤组成员")
    @PostMapping("/delete")
    public Result deleteAttendanceGroupUser(@RequestParam AttendanceUserDto attendanceUserDto){
        if(attendanceUserDto.getOpId()==null||attendanceUserDto.getAttGrId()==null||attendanceUserDto.getUserList()==null){
            return ResultUtil.error("参数缺失！");
        }
        return attendanceGroupUserService.deleteAttendanceGroupUser(attendanceUserDto.getOpId(),attendanceUserDto.getAttGrId(),attendanceUserDto.getUserList());
    }

    @ApiOperation(notes = "修改考勤组成员信息",value = "修改考勤组成员信息")
    @PostMapping("/update")
    public Result updateAttendanceGroupUser(@RequestParam AttendanceUserDto attendanceUserDto){
        if(attendanceUserDto.getOpId()==null||attendanceUserDto.getAttGrId()==null||attendanceUserDto.getAttendanceGroupUserList()==null){
            return ResultUtil.error("参数缺失！");
        }
        return attendanceGroupUserService.updateAttendanceGroupUser(attendanceUserDto.getOpId(),attendanceUserDto.getAttGrId(),attendanceUserDto.getAttendanceGroupUserList());
    }

    @ApiOperation(notes = "列举考勤组成员列表",value = "列举考勤组成员列表")
    @PostMapping("/list")
    public Result listAttendanceGroupUser(@RequestParam  String opId,@RequestParam String groupId){
        if(opId==null||groupId==null){
            return ResultUtil.error("参数缺失！");
        }

        return attendanceGroupUserService.listAttendanceGroupUser(opId,groupId);
    }


}

